package com.bytedance.improvingroad.activity

import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Looper
import android.os.PersistableBundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.viewbinding.ViewBinding
import com.bytedance.improvingroad.R

/**
 * Created by chenxiong
 * date 11/9/21
 */
abstract class BaseActivity: AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getLayoutId())
        init()
    }

    inline fun <reified T: BaseActivity> startActivity() {
        startActivity(Intent(this, T::class.java))
    }

    inline fun <reified T: BaseBindingActivity<*>> startActivityAndFinish(parseParamsCall: Intent.()->Unit = {}) {
        Intent(this,T::class.java).let { intent ->
            intent.parseParamsCall()
            startActivity(intent)
        }
    }


    abstract fun init()
    abstract fun getLayoutId(): Int
}

// ViewHodler回收复用
//        detachAndScrapAttachedViews(recycler!!)
//
//        val bottomPosition: Int
//        val itemCount = itemCount
//        bottomPosition = if (itemCount < CardConfig.MAX_SHOW_COUNT) {
//            0
//        } else {
//            // 布局了四张卡片 --- 4，5，6，7
//            itemCount - CardConfig.MAX_SHOW_COUNT
//        }
//
//        for (i in bottomPosition until itemCount) {
//
//            // 复用
//            val view = recycler!!.getViewForPosition(i)
//            addView(view)
//
//            measureChildWithMargins(view, 0, 0)
//
//            val widthSpace = width - getDecoratedMeasuredWidth(view)
//            val heightSpace = height - getDecoratedMeasuredHeight(view)
//
//            // 布局 ---draw -- onDraw ,onDrawOver, onLayout
//
//            // 布局 ---draw -- onDraw ,onDrawOver, onLayout
//            layoutDecoratedWithMargins(
//                view, widthSpace / 2, heightSpace / 2,
//                widthSpace / 2 + getDecoratedMeasuredWidth(view),
//                heightSpace / 2 + getDecoratedMeasuredHeight(view)
//            )
//
//            val level: Int = itemCount - i - 1
//            if (level > 0) {
//                if (level < CardConfig.MAX_SHOW_COUNT - 1) {
//                    view.translationY = CardConfig.TRANS_Y_GAP * level
//                    view.scaleX = 1 - CardConfig.SCALE_GAP * level
//                    view.scaleY = 1 - CardConfig.SCALE_GAP * level
//                } else {
//                    // 最下面的那个view 与前一个view 布局一样
//                    view.translationY = CardConfig.TRANS_Y_GAP * (level - 1)
//                    view.scaleX = 1 - CardConfig.SCALE_GAP * (level - 1)
//                    view.scaleY = 1 - CardConfig.SCALE_GAP * (level - 1)
//                }
//            }
//        }